home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-07-15 | 27.6 KB | 869 lines | [TEXT/MPS ] |
- // Copyright © 1989-1990 by Apple Computer, Inc. All rights reserved.
-
-
- #ifndef __DEMOTEXTDUMP__
- #include "DemoTextDump.h"
- #endif __DEMOTEXTDUMP__
-
- extern "C" char* memcpy(void*, void*, int);
- #define pstrcpy(p,q) memcpy(p, q, q[0]+1) // added for translation: Pascal strcpy
- extern "C" void printf(const char *, ...);
-
- // Menu numbers
- const short mFont = 10;
-
- // Command numbers
-
- const short cWidthFrame = 601; // View-width-determination commands
- const short cWidthView = 602;
- const short cWidthOnePage = 603;
-
- const short cHeightFrame = 604; // View-height-determination commands
- const short cHeightPages = 605;
- const short cHeightText = 606;
- const short cHeightConst = 607;
-
- const short cJustLeft = 608; // Justification commands
- const short cJustCenter = 609;
- const short cJustRight = 610;
-
- /*
- Command numbering scheme:
- const short styles = 1000
- const short sizes = 1100
- const short just = 1200
- const short fonts = 1300
- const short hiers = 1400
- const short colors = 1500
- */
-
- // Command numbers for typestyle attributes
- const short cPlainText = 1001;
- const short cBold = 1002;
- const short cItalic = 1003;
- const short cUnderline = 1004;
- const short cOutline = 1005;
- const short cShadow = 1006;
- const short cCondense = 1007;
- const short cExtend = 1008;
-
- // Command numbers for font-size commands
- const short cSizeChange = 1100;
- const short cSizeBase = 1100;
- const short cSizeMin = 1109;
- const short cSizeMax = 1124;
- // 1101-1197 reserved for font sizes 1-97 pts.
- const short cSizeGrow = 1198;
- const short cSizeShrink = 1199;
-
- // Command numbers to cover other stylistic changes
- const short cJustChange = 1200;
- const short cFontChange = 1300;
-
- // Command numbers for the hierarchial menu
- const short cStyle = 1401;
- const short cSize = 1402;
- const short cFont = 1403;
- const short cColor = 1404;
-
- // Command numbers for changing colors
- const short cColorChange = 1500;
- const short cColorText = 1501;
- const short cColorBackground = 1502;
-
- const short cXShowBreaks = 1601;
-
- // Constant for staggering windows
- const short kStaggerAmount = 16;
-
- // Constant for amount to relative size text selection
- const short kRelSizeAmount = 4;
-
- // Constants for the text specs resource
- const unsigned long kTextSpecsRsrcType = 'SPEC';
- const short kTextSpecsRsrcID = 1;
-
- // Constants for the text style resource
- const unsigned long kTextStyleRsrcType = 'STYL';
- const short kStylesRsrcID = 1;
- const short kElementsRsrcID = 2;
-
- // Constants for the print info resource
- const unsigned long kPrintInfoRsrcType = 'PRNT';
- const short kPrintInfoRsrcID = 1;
-
- // Constants for the prompts string list
- const short kPromptsRsrcID = 1001;
- const short kColTextPrompt = 1;
- const short kColBackPrompt = 2;
-
- // The 'File is too large' alert
- const short kFileTooBig = 1000;
-
- const short kHierDisplayedMBar = 131; // Displayed menus on hier. menu system
- const short kNonHierDisplayedMBar = 128; // Displayed menus on non-hier. system
-
- const short kHierMenuOffset = 1000; // Offset added to non-hier menu cmds to get
- // right #
-
- TextSpecs gDefaultSpecs; // Text specs as default for new documents
- short gStaggerCount;
- short gMenuOfs;
- Str255 gPromptString;
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- StringPtr GetPrompt(short index)
- {
- GetIndString(gPromptString, kPromptsRsrcID, index);
- return (StringPtr) &gPromptString;
- }
-
- //******************************************************************************************
- // T D e m o T e x t A p p l i c a t i o n
- //******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AInit
-
- pascal void TDemoTextApplication::IDemoTextApplication()
- {
-
- Str255 fontName;
- TTEView *aTEView;
-
- #if qNeedsHierarchialMenus == 0
- if (! gConfiguration.hasHierarchicalMenus) {
- gMBarDisplayed = kNonHierDisplayedMBar;
- gMenuOfs = 0;
- } else
- #endif
- {
- gMBarDisplayed = kHierDisplayedMBar;
- gMenuOfs = kHierMenuOffset;
- }
-
- IApplication(kFileType);
-
- if (! gFinderPrinting) {
- AddResMenu(GetMHandle(mFont), 'FONT');
-
- gStaggerCount = 0;
-
- SetStyle(cBold, bold);
- SetStyle(cUnderline, underline);
- SetStyle(cItalic, italic);
- SetStyle(cOutline, outline);
- SetStyle(cShadow, shadow);
- SetStyle(cCondense, condense);
- SetStyle(cExtend, extend);
- }
-
- // Instead of hard-wiring a default text style, get it from the TEView resource by
- aTEView = (TTEView*) DoCreateViews(NULL, NULL, kViewRsrcID, &gZeroVPt);
- FailNIL(aTEView);
- GetFontName(aTEView->fTextStyle.tsFont, fontName);
- //gDefaultSpecs.theTextFont = fontName; // Set up initial text specs
- pstrcpy(gDefaultSpecs.theTextFont, fontName); // Kludged Pascal string copy
- gDefaultSpecs.theTextFace = aTEView->fTextStyle.tsFace;
- gDefaultSpecs.theTextSize = aTEView->fTextStyle.tsSize;
- gDefaultSpecs.theTextColor = aTEView->fTextStyle.tsColor;
- gDefaultSpecs.theJustification = aTEView->fJustification;
- gDefaultSpecs.theBackColor = gRGBWhite;
- aTEView->Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal TDocument *TDemoTextApplication::DoMakeDocument(CmdNumber )
- {
- TTextDocument *aTextDocument;
-
- aTextDocument = new TTextDocument;
- FailNIL(aTextDocument);
- aTextDocument->ITextDocument();
- return aTextDocument;
- }
-
- //--------------------------------------------------------------------------------------------------
- #if qDebug
- #pragma segment ADebug
-
- pascal void TDemoTextApplication::IdentifySoftware()
- {
- printf("DemoText Source date: 23 April 86; Compiled: %s @ %s\n", __DATE__, __TIME__);
- inherited::IdentifySoftware();
- }
- #endif
-
- //******************************************************************************************
- // T T e x t D o c u m e n t
- //******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void TTextDocument::ITextDocument()
- {
- fDocText = NULL;
- IDocument(kFileType, kSignature, kUsesDataFork, kUsesRsrcFork, ! kDataOpen, ! kRsrcOpen);
-
- fTEView = NULL;
- fStyles = NULL;
- fElements = NULL;
- fDocText = NewPermHandle(0);
- FailNIL(fDocText);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AClose
-
- pascal void TTextDocument::Free()
- {
- if (fDocText)
- DisposHandle(fDocText);
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ANonRes
-
- pascal void TTextDocument::ChangeBackColor(RGBColor *newColor)
- {
- GrafPtr oldPort;
- TWindow *itsWindow;
-
- // ??? Is this right? Should we set the background color even if the view isn't
- // in a window yet?
- GetPort(&oldPort);
- SetPort((*fTEView->fHTE)->inPort);
- RGBBackColor(newColor);
- itsWindow = fTEView->GetWindow();
- if (itsWindow)
- itsWindow->ForceRedraw();
- SetPort(oldPort);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void TTextDocument::DoInitialState()
- {
- fTextSpecs = gDefaultSpecs;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- pascal void TTextDocument::DoMakeViews(Boolean forPrinting)
- {
- TView *aView;
- TStdPrintHandler *aHandler;
-
- if (forPrinting)
- // We're only finder printing--don't need a window, just the view being printed
- aView = DoCreateViews(this, NULL, kViewRsrcID, &gZeroVPt);
- else
- aView = NewTemplateWindow(kWindowRsrcID, (TDocument*) this);
-
- FailNIL(aView); // ??? Will we have already failed?
- aView = aView->FindSubView('TEVW');
- fTEView = (TTEView*) aView; // Must cast because FindSubView returns
- /// TView
- aHandler = new TStdPrintHandler;
- FailNIL(aHandler);
- aHandler->IStdPrintHandler((TDocument*) this, // its document
- (TView*) fTEView, // its view
- 0, // does not have square dots
- 1, // horzontal page size is fixed
- 0); // vertical page size is variable (could be
- // set
- // …to true on non-style TE systems)
- aHandler->fMinimalMargins = 0;
- ShowReverted();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- static SizeDeterminer sd; // for shared use by the following functions
- static Str255 aName; // which are used by TTextDocument::DoMenuCommand()
- static short menu;
- static short item;
- static TextStyle newStyle;
- static CmdNumber aCmdNumber;
- static TTextDocument *ttd; // kludged copy of "this"
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoSizeChange(CmdNumber base)
- {
- newStyle.tsSize = aCmdNumber - base;
- ttd->fTextSpecs.theTextSize = newStyle.tsSize;
- return ttd->fTEView->DoMakeStyleCommand(&newStyle, cSizeChange, doSize + doToggle);
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoRelSizeChange(short amount)
- {
- newStyle.tsSize = amount;
- ttd->fTextSpecs.theTextSize += amount;
- return ttd->fTEView->DoMakeStyleCommand(&newStyle, cSizeChange, doSize + addSize + doToggle);
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoFontChange()
- {
- GetItem(GetMHandle(menu), item, aName);
- GetFNum(aName, &newStyle.tsFont);
- //ttd->fTextSpecs.theTextFont = aName;
- pstrcpy(ttd->fTextSpecs.theTextFont, aName); // kludged Pascal string copy
- return ttd->fTEView->DoMakeStyleCommand(&newStyle, cFontChange, doFont + doToggle);
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoColTextChange()
- {
- RGBColor aColor;
- static Point P4040 = {0x0040, 0x0040};
-
- aColor = ttd->fTextSpecs.theTextColor;
- if (GetColor(P4040, GetPrompt(kColTextPrompt), &aColor, &newStyle.tsColor)) {
- ttd->fTextSpecs.theTextColor = newStyle.tsColor;
- return ttd->fTEView->DoMakeStyleCommand(&newStyle, cColorChange, doColor + doToggle);
- }
- return gNoChanges;
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static void DoColBackChange()
- {
- RGBColor aColor;
- static Point P4040 = {0x0040, 0x0040};
-
- aColor = ttd->fTextSpecs.theBackColor;
- if (GetColor(P4040, GetPrompt(kColBackPrompt), &aColor, &newStyle.tsColor)) {
- ttd->fTextSpecs.theBackColor = newStyle.tsColor;
- ttd->ChangeBackColor(&newStyle.tsColor);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoJustChange()
- {
- short newJust;
- TJustCommand *aJustChange;
-
- switch (aCmdNumber) {
- case cJustLeft: newJust = teJustLeft; break;
- case cJustCenter: newJust = teJustCenter; break;
- case cJustRight: newJust = teJustRight; break;
- }
- aJustChange = new TJustCommand;
- FailNIL(aJustChange);
- aJustChange->IJustCommand(ttd->fTEView, newJust);
- ttd->fTextSpecs.theJustification = newJust;
- return aJustChange;
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoPlainChange()
- {
- newStyle.tsFace = 0;
- ttd->fTextSpecs.theTextFace = 0;
- return ttd->fTEView->DoMakeStyleCommand(&newStyle, cStyleChange, doFace);
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static TCommand *DoStyleChange()
- {
- switch (aCmdNumber) {
- case cBold: newStyle.tsFace = bold; break;
- case cItalic: newStyle.tsFace = italic; break;
- case cUnderline: newStyle.tsFace = underline; break;
- case cOutline: newStyle.tsFace = outline; break;
- case cShadow: newStyle.tsFace = shadow; break;
- case cCondense: newStyle.tsFace = condense; break;
- case cExtend: newStyle.tsFace = extend; break;
- }
- if (newStyle.tsFace * ttd->fTextSpecs.theTextFace == newStyle.tsFace)
- ttd->fTextSpecs.theTextFace -= newStyle.tsFace;
- else
- ttd->fTextSpecs.theTextFace += newStyle.tsFace;
- return ttd->fTEView->DoMakeStyleCommand(&newStyle, cStyleChange, doFace + doToggle);
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static void InstallChangedDeterminer(VHSelect vhs)
- {
- if (sd != ttd->fTEView->fSizeDeterminer[vhs]) {
- ttd->fTEView->fSizeDeterminer[vhs] = sd;
-
- // If we changed the horizontal size determiner, we must
- // ask the TTEView to recompute the TE rectangles.
- if (vhs == h) {
- if (sd == sizeSuperView)
- ttd->fTEView->SuperViewChangedSize(&gZeroVPt, 1); // Don't care about deltas
- else if (sd == sizePage)
- ttd->fTEView->DoPagination();
- }
-
- ttd->fTEView->AdjustSize();
- ttd->fTEView->ForceRedraw();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static void DoWidthChange()
- {
- if (aCmdNumber == cWidthFrame)
- sd = sizeSuperView;
- else if (aCmdNumber == cWidthOnePage)
- sd = sizePage;
- else
- sd = sizeFixed;
-
- InstallChangedDeterminer(h); // NB: The following is not undoable in the
- // current version
- }
-
- //--------------------------------------------------------------------------------------------------
-
- pascal static void DoHeightChange()
- {
- switch (aCmdNumber) {
- case cHeightFrame: sd = sizeSuperView; break;
- case cHeightPages: sd = sizeFillPages; break;
- case cHeightText: sd = sizeVariable; break;
- case cHeightConst: sd = sizeFixed; break;
- }
-
- InstallChangedDeterminer(v); // NB: The following is not undoable in the
- // current version
- }
-
- pascal TCommand *TTextDocument::DoMenuCommand(CmdNumber theCmdNumber)
- {
- aCmdNumber = theCmdNumber; // for use in formerly nested procedures
- ttd = this; // ditto
-
- CmdToMenuItem(aCmdNumber, &menu, &item);
-
- if (menu == mFont) {
- return DoFontChange();
- } else {
- if (aCmdNumber >= cSizeMin && aCmdNumber <= cSizeMax)
- return DoSizeChange(cSizeBase);
- else if (aCmdNumber == cSizeGrow)
- return DoRelSizeChange(kRelSizeAmount);
- else if (aCmdNumber == cSizeShrink)
- return DoRelSizeChange( - kRelSizeAmount);
- else if (aCmdNumber >= cJustLeft && aCmdNumber <= cJustRight)
- return DoJustChange();
- else if (aCmdNumber == cPlainText)
- return DoPlainChange();
- else if (aCmdNumber >= cBold && aCmdNumber <= cExtend)
- return DoStyleChange();
- else if (aCmdNumber == cColorText)
- return DoColTextChange();
- else if (aCmdNumber == cColorBackground)
- DoColBackChange();
- else if (aCmdNumber >= cWidthFrame && aCmdNumber <= cWidthOnePage)
- DoWidthChange();
- else if (aCmdNumber >= cHeightFrame && aCmdNumber <= cHeightConst)
- DoHeightChange();
- // ??? Next line has got to change ??????????
- else if (aCmdNumber == cXShowBreaks)
- return fDocPrintHandler->DoMenuCommand(cShowBreaks);
- else
- return inherited::DoMenuCommand(aCmdNumber);
- }
- return gNoChanges;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- pascal void TTextDocument::DoNeedDiskSpace(long *dataForkBytes, long *rsrcForkBytes)
- {
- TEStyleHandle styles;
- STHandle elements;
-
- *dataForkBytes += GetHandleSize(fDocText);
-
- *rsrcForkBytes += kPrintInfoSize + kRsrcTypeOverhead + kRsrcOverhead;
-
- if (fTEView->fStyleType == kWithStyle && fTEView->fHTE) {
- fTEView->ExtractStyles(&styles, &elements);
- *rsrcForkBytes += GetHandleSize(Handle(styles)) + kRsrcTypeOverhead +
- kRsrcOverhead + GetHandleSize(Handle(elements)) + kRsrcTypeOverhead +
- kRsrcOverhead;
- }
-
- *rsrcForkBytes += sizeof(TextSpecs) + kRsrcTypeOverhead + kRsrcOverhead;
-
- // Get resource file overhead
- inherited::DoNeedDiskSpace(dataForkBytes, rsrcForkBytes);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- pascal void TTextDocument::DoRead(short aRefNum, Boolean , Boolean )
- {
- long numChars;
- TextSpecsHdl hTextSpecs;
- Handle hPrintInfo;
-
- FailOSErr(GetEOF(aRefNum, &numChars)); // Read in the text
-
- if (numChars > kUnlimited) { // The file may have been created by…
- gApplication->ShowError(0, msgAlert + kFileTooBig); // …someone else - limit it to 32K!
- numChars = kUnlimited;
- }
-
- SetHandleSize(fDocText, numChars);
- FailMemError();
- FailOSErr(FSRead(aRefNum, &numChars, *fDocText));
-
- fStyles = TEStyleHandle(GetResource(kTextStyleRsrcType, kStylesRsrcID)); // Read in the TEStyleRec
- if (fStyles)
- DetachResource(Handle(fStyles));
-
- fElements = // Read in the STElement array
- STHandle(GetResource(kTextStyleRsrcType, kElementsRsrcID));
- if (fElements)
- DetachResource(Handle(fElements));
-
- hTextSpecs = // Read the text specs resource
- TextSpecsHdl(GetResource(kTextSpecsRsrcType, kTextSpecsRsrcID));
- if (hTextSpecs)
- fTextSpecs = **hTextSpecs;
- else
- DoInitialState();
-
- hPrintInfo = // Read the print info resource
- GetResource(kPrintInfoRsrcType, kPrintInfoRsrcID);
- if (hPrintInfo) { // no print info resources was saved
- if (fPrintInfo == NULL) {
- fPrintInfo = NewPermHandle(kPrintInfoSize);
- FailNIL(fPrintInfo);
- }
- BlockMove(*hPrintInfo, *fPrintInfo, kPrintInfoSize);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TTextDocument::DoSetupMenus()
- {
- Boolean hasColor;
- Boolean hasStyle;
- Boolean checkPlain;
- Boolean checkSize;
- Boolean checkFont;
- Boolean specChange;
- short just;
- short item;
- short fnt;
- short c;
- short aMode;
- Style aFace;
- SizeDeterminer sd;
- MenuHandle aMenuHandle;
- Str255 aName;
- TextStyle aStyle;
- short theFont;
- short startOfSelection, endOfSelection;
- Str255 aStr255;
-
- inherited::DoSetupMenus();
-
- hasColor = gConfiguration.hasColorQD;
- hasStyle = gConfiguration.hasStyleTextEdit;
-
- #if qNeedsStyleTextEdit == 0
- if (! hasStyle) {
- //aStr255 = fTextSpecs.theTextFont;
- pstrcpy(aStr255, fTextSpecs.theTextFont); // kludged Pascal string copy
- GetFNum(aStr255, &aStyle.tsFont);
- aStyle.tsFace = fTextSpecs.theTextFace;
- aStyle.tsSize = fTextSpecs.theTextSize;
- aStyle.tsColor = fTextSpecs.theTextColor;
- checkPlain = aStyle.tsFace = 0;
- checkFont = 1;
- } else
- #endif
- {
- startOfSelection = (*fTEView->fHTE)->selStart;
- endOfSelection = (*fTEView->fHTE)->selEnd;
- aMode = doFace;
- checkPlain = fTEView->ContinuousStyle(startOfSelection, endOfSelection, &aMode, &aStyle) &&
- (aStyle.tsFace == 0);
-
- aMode = doAll;
- aStyle.tsFace = bold | italic | underline | outline | shadow | extend | condense;
- specChange = fTEView->ContinuousStyle(startOfSelection, endOfSelection, &aMode, &aStyle);
- checkFont = ((aMode & doFont) != 0);
- }
-
- aMenuHandle = GetMHandle(mFont);
- // If specs have changed AND EITHER an old-style record OR the font's continuous - Ed.
- specChange = fTEView->fSpecsChanged && ((! hasStyle) || checkFont);
-
- GetFontName(aStyle.tsFont, aName); // Get real font number in case tsFont is
- GetFNum(aName, &theFont); // …the system or application font.
- for (item=1; item <= CountMItems(aMenuHandle); item++) {
- // There can be more than 31 menu entries with scrolling menus, but trying to enable
- // an item with number > 31 is bad news. If the menu itself is enabled (which it
- // will be in MacApp if any of the first 31 items is enabled), then the extras
- // will always be enabled.
- if (item <= 31)
- EnableItem(aMenuHandle, item);
- if (checkFont) {
- GetItem(aMenuHandle, item, aName);
- GetFNum(aName, &fnt);
- CheckItem(aMenuHandle, item, fnt == theFont);
- }
- }
-
- EnableCheck(cXShowBreaks, 1, ((TStdPrintHandler*)fDocPrintHandler)->fShowBreaks);
-
- sd = fTEView->fSizeDeterminer[h]; // Enable size determiner related menu items
-
- EnableCheck(cWidthFrame, 1, (sd == sizeSuperView));
- EnableCheck(cWidthOnePage, 1, (sd == sizePage));
- EnableCheck(cWidthView, 1, (sd == sizeFixed));
-
- sd = fTEView->fSizeDeterminer[v];
- EnableCheck(cHeightFrame, 1, (sd == sizeSuperView));
- EnableCheck(cHeightPages, 1, (sd == sizeFillPages));
- EnableCheck(cHeightText, 1, (sd == sizeVariable));
- EnableCheck(cHeightConst, 1, (sd == sizeFixed));
-
- just = fTEView->fJustification; // Enable justification related menu items
- EnableCheck(cJustLeft, 1, (just == teJustLeft));
- EnableCheck(cJustCenter, 1, (just == teJustCenter));
- EnableCheck(cJustRight, 1, (just == teJustRight));
-
- #if qNeedsHierarchialMenus == 0
- if (gConfiguration.hasHierarchicalMenus)
- #endif
- {
- Enable(cStyle, 1); // Enable sub-menus
- Enable(cSize, 1);
- Enable(cFont, 1);
- Enable(cColor, hasColor);
- }
-
- aFace = aStyle.tsFace;
-
- EnableCheck(cPlainText, 1, checkPlain); // Enable normal Style menu items
- EnableCheck(cBold, 1, aFace & bold);
- EnableCheck(cItalic, 1, aFace & italic);
- EnableCheck(cUnderline, 1, aFace & underline);
- EnableCheck(cOutline, 1, aFace & outline);
- EnableCheck(cShadow, 1, aFace & shadow);
- EnableCheck(cCondense, 1, aFace & condense);
- EnableCheck(cExtend, 1, aFace & extend);
-
- for (c=cSizeMin; c<=cSizeMax; c++) {
- if (hasStyle && ((aMode & doSize) == 0))
- checkSize = 0;
- else
- checkSize = (c - cSizeBase) == aStyle.tsSize;
- EnableCheck(c, 1, checkSize);
- if (fTEView->fSpecsChanged) {
- if ( ((! hasStyle) || // If the record isn't styled, or
- (aMode & doFont)) && // …it _is_ styled and font is continuous
- RealFont(aStyle.tsFont,c-cSizeBase) ) // …and the size is a real one
- aFace = outline; // …then we outline it
- else
- aFace = 0;
- SetStyle(c, aFace);
- }
- }
-
- Enable(cSizeGrow, 1);
- Enable(cSizeShrink, 1);
-
- Enable(cColorText, hasColor);
- Enable(cColorBackground, hasColor);
-
- fTEView->fSpecsChanged = 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AWriteFile
-
- pascal void TTextDocument::DoWrite(short aRefNum, Boolean )
- {
- long numChars;
- TextSpecsHdl hTextSpecs;
- Handle tempHandle;
- TEStyleHandle styles;
- STHandle elements;
-
- // Write out the text
- numChars = GetHandleSize(fDocText);
- FailOSErr(FSWrite(aRefNum, &numChars, *fDocText));
-
- if (fTEView->fStyleType == kWithStyle) {
- fTEView->ExtractStyles(&styles, &elements);
- FailOSErr(HandToHand((Handle*)&styles));
- AddResource(Handle(styles), kTextStyleRsrcType, kStylesRsrcID, "\p");
- FailResError();
- FailOSErr(HandToHand((Handle*)&elements));
- AddResource(Handle(elements), kTextStyleRsrcType, kElementsRsrcID, "\p");
- FailResError();
- }
-
- // Write the text specification resource, after converting it to a handle
- hTextSpecs = TextSpecsHdl(NewHandle(sizeof(TextSpecs)));
- FailNIL(hTextSpecs);
- **hTextSpecs = fTextSpecs;
- AddResource(Handle(hTextSpecs), kTextSpecsRsrcType, kTextSpecsRsrcID, "\p");
-
- FailResError();
-
- // Write the print info resource. Note we can't use MacApp for this because MacApp
- // will write the print info into the data fork. Note also--we must copy the print
- // info resource to another handle because the Resource Manager will dispose of the
- // resource handles when a resource fork is closed.
- if (fPrintInfo) { // Make sure we have one of these guy
- tempHandle = fPrintInfo;
- FailOSErr(HandToHand(&tempHandle));
- AddResource(tempHandle, kPrintInfoRsrcType, kPrintInfoRsrcID, "\p");
- FailResError();
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AClose
-
- pascal void TTextDocument::FreeData()
- {
- SetHandleSize(fDocText, 0);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ARes
-
- pascal void TTextDocument::SetSpecStyle()
- {
- short theFont;
- TextStyle theTS;
- Str255 aStr255;
-
- //aStr255 = fTextSpecs.theTextFont;
- pstrcpy(aStr255, fTextSpecs.theTextFont); // kludged Pascal string copy
- GetFNum(aStr255, &theFont);
- SetTextStyle(&theTS, theFont, fTextSpecs.theTextFace,
- fTextSpecs.theTextSize, &fTextSpecs.theTextColor);
- fTEView->SetOneStyle(0, 0, doAll, &theTS, kDontRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AReadFile
-
- pascal void TTextDocument::ShowReverted()
- {
- RGBColor aColor;
-
- fTEView->StuffText(fDocText); // put in the text
- TESetSelect(0, 0, fTEView->fHTE);
- if (fStyles && fElements) // If we're able, stuff style info
- fTEView->StuffStyles(fStyles, fElements);
- else
- SetSpecStyle();
- #if qNeedsColorQD == 0
- if (gConfiguration.hasColorQD)
- #endif
- {
- aColor = fTextSpecs.theBackColor;
- ChangeBackColor(&aColor);
- }
- fTEView->SetJustification(fTextSpecs.theJustification, kDontRedraw);
- inherited::ShowReverted();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AFields
-
- pascal void TTextDocument::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- (*DoToField)("\pTTextDocument", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\pfDocText", (Ptr) &fDocText, bHandle, DoToField_StaticLink);
- (*DoToField)("\pfTEView", (Ptr) &fTEView, bObject, DoToField_StaticLink);
- (*DoToField)("\p fTextSpecs", NULL, bClass, DoToField_StaticLink);
- (*DoToField)("\p theTextFont", (Ptr) &fTextSpecs.theTextFont, bString, DoToField_StaticLink);
- (*DoToField)("\p theTextFace", (Ptr) &fTextSpecs.theTextFace, bStyle, DoToField_StaticLink);
- (*DoToField)("\p theTextSize", (Ptr) &fTextSpecs.theTextSize, bInteger, DoToField_StaticLink);
- (*DoToField)("\p theTextColor", (Ptr) &fTextSpecs.theTextColor, bRGBColor, DoToField_StaticLink);
- (*DoToField)("\p theJustification",(Ptr) &fTextSpecs.theJustification, bInteger, DoToField_StaticLink);
- (*DoToField)("\p theBackColor", (Ptr) &fTextSpecs.theBackColor, bRGBColor, DoToField_StaticLink);
- inherited::Fields(DoToField, DoToField_StaticLink);
- }
-
- //******************************************************************************************
- // T J u s t C o m m a n d
- //******************************************************************************************
- //--------------------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- pascal void TJustCommand::IJustCommand(TTEView *itsTEView, short itsNewJust)
- {
- ICommand(cJustChange, itsTEView->fDocument, NULL, NULL);
- fTEView = itsTEView;
- fOldJust = itsTEView->fJustification;
- fNewJust = itsNewJust;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- pascal void TJustCommand::DoIt()
- {
- fTEView->SetJustification(fNewJust, kRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- pascal void TJustCommand::RedoIt()
- {
- DoIt();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment ADoCommand
-
- pascal void TJustCommand::UndoIt()
- {
- fTEView->SetJustification(fOldJust, kRedraw);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment AFields
-
- pascal void TJustCommand::Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr,
- short fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink)
- {
- DoToField("\pTJustCommand", NULL, bClass, DoToField_StaticLink);
- DoToField("\pfTEView", (Ptr) &fTEView, bObject, DoToField_StaticLink);
- DoToField("\pfOldJust", (Ptr) &fOldJust, bInteger, DoToField_StaticLink);
- DoToField("\pfNewJust", (Ptr) &fNewJust, bInteger, DoToField_StaticLink);
- inherited::Fields(DoToField, DoToField_StaticLink);
- }
-